home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group94a.txt
/
000056_icon-group-sender _Sun Feb 20 18:29:49 1994.msg
< prev
next >
Wrap
Internet Message Format
|
1994-08-19
|
2KB
Received: by cheltenham.cs.arizona.edu; Sun, 20 Feb 1994 19:27:52 MST
From: pab (Peter A. Bigot)
Message-Id: <9402210129.AA26505@omnia.cs.arizona.edu>
Subject: generating both [lr]values of records
To: icon-group
Date: Sun, 20 Feb 1994 18:29:49 -0700 (MST)
X-Mailer: ELM [version 2.4 PL23]
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Content-Length: 1807
Status: RO
Errors-To: icon-group-errors@cs.arizona.edu
I have a large number of different records (representing syntactic terms, if
it matters), which form trees, and I want to replace subtrees with a value
which is based on the current subtree (in effect, implement variable
substitution: t [expr/X]).
I don't care about the old value of the records, so an update-in-place would
be nice. I also don't want to enumerate the different types of records, and
handle them with separate cases. So, using the ! generator on the record,
and the neat trick that it generates lvalues, looks like the way to go.
I.e., "every !rec := expr". But: how can I use the generated element (of
!rec) as part of the rhs of the assignment?
It seems to me I've seen this before, but can't recall the necessary
incantation.
Here are a few attempts, one of which works---but I'd like a better way.
record A (a1, a2, a3) # some arbitrary record
procedure main ()
ar := A (1, 2, 3)
# Attempt one: naively assume we can preserve the lvalue
every (t := !ar) do
t := (.t+1)
writes (image (ar), " -- ")
every writes (! ar, " ")
write ()
# Attempt two: maybe we can fool it
every (t := !ar) := (t+1)
writes (image (ar), " -- ")
every writes (! ar, " ")
write ()
# Brute force: this works, but it's gotta be inefficient in both
# time and space
nr := list()
every put (nr, !ar + 1)
ar := type(ar) ! nr # -10 points for using arcane features....
writes (image (ar), " -- ")
every writes (! ar, " ")
write ()
# What I'd like:
# every !ar := (¤tgenelt)+1
# but for some reason that doesn't work....
end # main
Is there a better way?
--
Peter A. Bigot -- pab@CS.Arizona.EDU
Dept. of Computer Science, University of Arizona, Tucson AZ